
export const taskType = {
  inspection: 'HEALTH_CHECK',
  infoCollect: 'DATA_COLLECT',
  securityManage: 'SECURITY_MANAGE',
};


export function downloadTheFile(data, fileName) {
  const blob = new Blob([data]);
  const a = document.createElement('a');
  const body = document.querySelector('body');
  a.download = fileName;
  a.style.display = 'none';
  a.href = window.URL.createObjectURL(blob);
  body.appendChild(a);
  a.click();
  window.URL.revokeObjectURL(a.href);
  body.removeChild(a);
}

function fnRatioSize(a, b, colName, referenceList) {
  if (referenceList) {
    return referenceList[a[colName]] - referenceList[b[colName]];
  }
  return a[colName] < b[colName];
}

export function sortCol(colName, type, referenceList) {
  // type为ascending或descending
  // referenceList为排序参照，可选
  let rev = 1;
  if (type && type !== 'ascending') {
    rev = -1;
  }
  return function (a, b) {
    const result = fnRatioSize(a, b, colName, referenceList);
    if (result) {
      return rev * 1;
    }
    if (result === 0) {
      return 0;
    }
    return rev * -1;
  };
}

export function fnIsError(code) {
  if (String(code)[6] === '2') {
    return true;
  }
  return false;
}
